if($.amud==null)
	$.amud={};
$.amud.items={
	action:function(){
		items="<br />";
		for(var item in $.amud.core.user.items){
			items=items+$.amud.items.formatItem($.amud.core.user.items[item],item);
		}
		return items;
	},
	formatItem:function(item,slot){
		ret="<div class='item'>";
		if(slot!=null){
			ret+="<span class='item_slot'>"+slot+":</span>";
		}
		if(item!=null && item.id!=null){
			if(item.stack>1){
				stack="("+item.stack+")";
			}else{
				stack="";
			}
            if(item.type==null){
                item.type='ERROR';
            }
			ret+="<div class='item_icon "+item.type.replace(' ','_')+"'></div>";
			ret+="<span class='item_description'>"+item.type+stack+"</span>";
			ret+="<span class='item_text'>Dur:</span>";
			ret+="<span class='item_currDurability'>"+item.currDurability+"</span>";
			ret+="<span class='item_text'>/</span>";
			ret+="<span class='item_maxDurability'>"+item.maxDurability+"</span>";
			ret+="<span class='item_text'>Weight:</span>";
			ret+="<span class='item_weight'>"+item.weight+"</span>";


			var capabilities=[];

			if(item.status!=null){
				for(var status in item.status){
					if(item.status[status].capabilities!=null){
						var level = parseFloat(item.status[status].level);
						for(var cap in item.status[status].capabilities){
							if(capabilities[cap]==null){
								capabilities[cap]=0;
							}
							capabilities[cap]+=parseFloat(item.status[status].capabilities[cap])*level;
						}
					}
				}
				if($.amud.core.sizeOf(capabilities)>0){
					ret+="<div class='item_capabilities'><span class='item_capabilities_title'>Capabilities:</span>";
					for(var cap in capabilities){
						ret+="<span class='item_capability_label'>"+cap+":</span>";
						ret+="<span class='item_capability "+cap.replace(' ','_')+"'>"+capabilities[cap]+"</span>";
					}
					ret+="</div>";
				}
			}
			if(item.container!=null){
				ret+="<div class='item_content'>";
                ret+="<div class='item_content_title'>Content</div>";
				for(var index in item.container.items){
					ret+=$.amud.items.formatItem(item.container.items[index]);
				}
				ret+="</div>";
			}
		}else{
			ret+="<span class='item_description'> - </span>";
		}
		ret+="</div>";
		return ret;
	},
	help:'<span class="help_command">items</span><span class="help_description">(local) see your items</span>',
	cmd:'items',
	register:function(){
		$.amud.core.addCommand($.amud.items.cmd,$.amud.items.action,$.amud.items.help);
	}
}

$(document).bind('login', $.amud.items.register);
